package com.htht.job.executor.service;

import com.alibaba.fastjson.JSON;
import com.htht.job.core.api.DubboService;
import com.htht.job.core.biz.model.ReturnT;
import com.htht.job.core.util.ResultUtil;
import com.htht.job.executor.model.fileinfo.FileInfo;
import com.htht.job.executor.model.ftp.Ftp;
import com.htht.job.executor.model.product.Product;
import com.htht.job.executor.model.productfileinfo.ProductFileInfo;
import com.htht.job.executor.service.fileinfo.FileInfoService;
import com.htht.job.executor.service.ftp.FtpService;
import com.htht.job.executor.service.monitor.MonitorService;
import com.htht.job.executor.service.product.ProductService;
import com.htht.job.executor.service.productfileinfo.ProductFileInfoService;
import com.htht.job.executor.service.shard.ShardingService;

import com.htht.job.vo.Monitor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by zzj on 2018/1/2.
 */
@Transactional
@Service("dubboService")
public class DubboServiceImpl implements DubboService {
	@Autowired
	private ProductService productService;
	@Autowired
	private ProductFileInfoService productFileInfoService;
	@Autowired
	private ShardingService shardingService;
	@Autowired
	private FtpService ftpService;
	@Autowired
	private MonitorService monitorService;
	@Autowired
	private FileInfoService fileInfoService;

	/**
	 * ftp
	 * 
	 * 按照id查询数据
	 */
	public Ftp getById(String id) {
		return ftpService.getById(id);
	}

	/**
	 * 修改FTP实体信息
	 * 
	 * @param ftp
	 *            实体对象
	 * @return 返回1 修改成功 0 修改失败
	 * @author miaowei 2018-01-24
	 */
	public int updeat(Ftp ftp) {
		return this.ftpService.updeat(ftp);
	}

	/**
	 * 删除FTP实体信息
	 * 
	 * @param id
	 *            需要删除的实体主键
	 * @return 1 删除成功 0删除失败
	 * @author miaowei 2018-01-24
	 */
	public int del(String id) {
		return this.ftpService.del(id);
	}

	public ResultUtil<List<String>> execute(String params, String handler,
			Map fixmap, Map dymap) {
		return shardingService.execute(params, handler, fixmap, dymap);
	}

	public Map<String, Object> pageListProduct(int start, int length,
			Product product) {
		Map<String, Object> map = productService.pageList(start, length,
				product);
		return map;
	}

	public Product saveProduct(Product product) {
		Product p = productService.saveProduct(product);
		return p;
	}

	public ReturnT<String> deleteProduct(String id) {
		ReturnT<String> r = productService.deleteProduct(id);
		return r;
	}

	public List<Product> findALlProduct() {
		return productService.findALlProduct();
	}

	public Map<String, Object> pageListProductFileInfo(int start, int length,
			ProductFileInfo productFileInfo) {
		Map<String, Object> map = productFileInfoService.pageList(start,
				length, productFileInfo);
		return map;
	}

	public ProductFileInfo saveProductFileInfo(ProductFileInfo productFileInfo) {
		ProductFileInfo p = productFileInfoService
				.saveProductFileInfo(productFileInfo);
		return p;
	}

	public ProductFileInfo deleteProductFileInfo(String id) {
		ProductFileInfo p = productFileInfoService.deleteProductFileInfo(id);
		return p;
	}

	public String findSelectFtp() {
		List<Ftp> list = ftpService.findAll();
		List<Map> mapList = new ArrayList<Map>();
		for (int i = 0; i < list.size(); i++) {
			Map map = new HashMap();
			map.put("id", list.get(i).getId());
			map.put("text", list.get(i).getName());
			mapList.add(map);
		}
		return JSON.toJSONString(mapList);
	}
    public List<Monitor> findAllMonitor(){
		return monitorService.findAll();
	}
	public List<FileInfo> findFileInfoByWhere(String id){
		return fileInfoService.findByWhere(id);
	}
}
